package org.shangrila.bme.mb;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.shangrila.app.sys.shiro.SecUtil;
import org.shangrila.app.wechat.utils.AccessWxUtil;
import org.shangrila.app.wechat.utils.WeChatUtil;
import org.shangrila.bme.eo.BmeContProd;
import org.shangrila.bme.eo.BmeContPurch;
import org.shangrila.bme.eo.BmeContract;
import org.shangrila.comm.dao.DbAccess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Named
@SessionScoped
public class NullTestMB implements Serializable {
	private static final long serialVersionUID = -50034441213217112L;
	private final Logger log = LoggerFactory.getLogger(this.getClass());

	private List<BmeContract> voc = new ArrayList<BmeContract>(); 
	private List<BmeContProd> vod = new ArrayList<BmeContProd>(); 
	private List<BmeContPurch> vop = new ArrayList<BmeContPurch>(); 

	private BmeContract bc = new BmeContract(); 
	private BmeContProd bd = new BmeContProd(); 
	private BmeContPurch bp = new BmeContPurch(); 
	
	private String operator;
	@Inject
	private DbAccess db;

	@PostConstruct
    public void init() {
		try{
			setOperator(SecUtil.getCachedShiroUser().getUserno());
		}
		catch(Exception ex){
			setOperator("wfm");
		}
    }

	public String weixinAction() {
		WeChatUtil.sendTextMessage(SecUtil.getCachedShiroUser().getWxno(),"\n发送微信消息成功！");

		log.info("weixin..." + SecUtil.getCachedShiroUser().getWxno());
		
		return null;
	}

         
    //查询信息
	public String queryAction() {
		voc = new ArrayList<BmeContract>(); 
		vod = new ArrayList<BmeContProd>(); 
		vop = new ArrayList<BmeContPurch>(); 
		BmeContract bc = new BmeContract(); 
		BmeContProd bd = new BmeContProd(); 
		BmeContPurch bp = new BmeContPurch(); 
		StringBuilder sql = new StringBuilder("SELECT m FROM BmeContract m Where m.id='20180730'");
		voc = db.findBySql(sql.toString(),null);
		//db.refreshEntityManager(voc);
		log.info("queryAction..." + sql);
		log.info("voc..." + voc.size());
		vod = voc.get(0).getBmeContProds();
		vop = voc.get(0).getBmeContPurches();
		bc = voc.get(0);
		db.refreshEntityManager(bc);

		bd = vod.get(0);
		bp = vop.get(0);
		log.info("voc..." + bc.getName());
		log.info("vod..." + bd.getContName());
		log.info("vop..." + bp.getContName());
		
		return null;
	}

	public List<BmeContract> getVoc() {
		return voc;
	}

	public void setVoc(List<BmeContract> voc) {
		this.voc = voc;
	}

	public List<BmeContProd> getVod() {
		return vod;
	}

	public void setVod(List<BmeContProd> vod) {
		this.vod = vod;
	}

	public List<BmeContPurch> getVop() {
		return vop;
	}

	public void setVop(List<BmeContPurch> vop) {
		this.vop = vop;
	}

	public BmeContract getBc() {
		return bc;
	}

	public void setBc(BmeContract bc) {
		this.bc = bc;
	}

	public BmeContProd getBd() {
		return bd;
	}

	public void setBd(BmeContProd bd) {
		this.bd = bd;
	}

	public BmeContPurch getBp() {
		return bp;
	}

	public void setBp(BmeContPurch bp) {
		this.bp = bp;
	}

	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}
	
}